package com.budweiser.user.dao;

import com.budweiser.model.user.User;
import com.budweiser.model.user.UserCredential;
import org.apache.ibatis.annotations.*;

@Mapper
public interface UserCredentialsDao {
	/***
	 * 根据用户名查询用户信息
	 * 
	 * @param username
	 * @return
	 */
	@Select("select u.* from sys_user u inner join sys_user_credentials c on c.userId = u.id where c.username = #{username} and u.deleteStatus =0")
	User findUserByUsername(String username);

	/***
	 * 根据用户名查询用户类型
	 * 
	 * @param username
	 * @return
	 */
	@Select("select * from sys_user_credentials   where username = #{username} ")
	UserCredential findByUsername(String username);

	/***
	 * 根据用户名，id不能ID查询用户类型
	 * 
	 * @param username
	 * @param id
	 * @return
	 */
	@Select("select * from sys_user_credentials   where username = #{username} and userId !=#{id}")
    UserCredential findByUsernameAndNoId(@Param("username") String username, @Param("id") Long id);

	/***
	 * 新增用户类型
	 * 
	 * @param userCredential
	 */
	@Insert("insert into sys_user_credentials(username, type, userId) values(#{username}, #{type}, #{userId})")
	void save(UserCredential userCredential);
	/****
	 * 删除
	 * @param username
	 */
	@Delete(" delete from sys_user_credentials  where username = #{username} ")
	void deleteByName(String username);
}
